<template>
  <div>
  <home-header></home-header>
  <home-swiper :items="items"></home-swiper>
  <home-icons :icons="icons"></home-icons>
  <home-recommend :recomlists="recomlists"></home-recommend>
  <home-weekend :weeklists="weeklists"></home-weekend>
  </div>
</template>

<script>
import HomeHeader from '../components/Header'
import HomeSwiper from '../components/Swiper'
import HomeIcons from '../components/Icons'
import HomeRecommend from '../components/Recommend'
import HomeWeekend from '../components/Weekend'
import axios from 'axios'
import { mapState } from 'vuex'

export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },
  data () {
    return {
      // city: '',
      lastCity: '',
      items: [],
      icons: [],
      recomlists: [],
      weeklists: []
    }
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo () {
      axios.get('/mock/index.json?city=' + this.city).then(res => {
        res = res.data
        console.log(res.data)
        if (res.ret && res.data) {
          const data = res.data
          // this.city = data.city
          this.items = data.items
          this.icons = data.icons
          this.recomlists = data.recomlists
          this.weeklists = data.weeklists
        }
      })
    }
  },
  mounted () {
    this.lastCity = this.city
    this.getHomeInfo()
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>
